﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum ConnectionPointType
{
    In,
    Out
}
public class ConnectPoint
{
    public Rect rect;
    public ConnectionPointType type;
    public Node node;
    public GUIStyle style;

    public Action<ConnectPoint> OnClickConnectPoint;

    public ConnectPoint(Node node,ConnectionPointType type,GUIStyle style,Action<ConnectPoint> OnClickConnectPoint)
    {
        this.node = node;
        this.type = type;
        this.style = style;
        this.OnClickConnectPoint = OnClickConnectPoint;
        rect = new Rect(0,0,10f,20f);
    }
    /// <summary>
    /// 绘制节点按钮（输入，输出）
    /// </summary>
    public void Draw()
    {
        rect.y = node.rect.y + (node.rect.height*0.5f-rect.height*0.5f);
        switch (type)
        {
            case ConnectionPointType.In:
                rect.x = node.rect.x - rect.width + 8f;
                break;
            case ConnectionPointType.Out:
                rect.x = node.rect.x + node.rect.width - 8f;
                break;
            default:
                break;
        }
        if (GUI.Button(rect," ",style))
        {
            if (OnClickConnectPoint!=null)
            {
                OnClickConnectPoint(this);
            }
        }
    }
}
